The obvious reason for this nickname might appear to be Maryland's position in respect of the Mason–Dixon line, which defines its borders with both Pennsylvania (to the north) and Delaware (to the east).
But apparently it's nothing to do with that.
The 'Old Line' in question was formed by 400 soldiers of the 1st Maryland Regiment who repeatedly charged a numerically superior British force, during the Battle of Long Island during the American War of Independence, sustaining heavy casualties, but allowing General Washington to evacuate the bulk of his troops to Manhattan.
The above information is from Wikipedia, but the Maryland government agrees: "According to some historians, General George Washington bestowed the name 'Old Line State' and thereby associated Maryland with its regular line troops, the Maryland Line, who served courageously in many Revolutionary War battles. For a closer examination of the background on this nickname, see: The Origin of the 'Old Line State', by Ryan Polk (2005)."
© Haydn Thompson 2021